from datetime import datetime
from app.extensions import db

class PlanConfig(db.Model):
    """智能计划配置表模型"""
    __tablename__ = 'plan_config'
    
    config_id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='配置唯一标识')
    daily_new = db.Column(db.SmallInteger, nullable=False, comment='每日新任务量')
    daily_review = db.Column(db.SmallInteger, nullable=False, comment='每日复习任务量')
    max_repeat = db.Column(db.SmallInteger, nullable=False, comment='最大重复次数')
    enable_time = db.Column(db.DateTime, default=datetime.now, comment='启用时间')
    
    # 逻辑外键字段
    student_id = db.Column(db.Integer, db.ForeignKey('student.student_id'), 
                        nullable=False, comment='学生ID')
    def to_dict(self):
        return {
            'config_id': self.config_id,
            'daily_new': self.daily_new,
            'daily_review': self.daily_review,
            'max_repeat': self.max_repeat,
            'enable_time': self.enable_time,
            'student_id': self.student_id
        }
    def __repr__(self):
        return f'<PlanConfig for Student {self.student_id}>'